// gzip
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
)

func GetPathWindows() string {
	file, _ := exec.LookPath(os.Args[0])
	//fmt.Println(file)
	path, _ := filepath.Abs(file)
	//fmt.Println(path)
	splist := strings.Split(path, "\\")
	size := len(splist)
	splist = strings.Split(path, splist[size-1])
	ret := strings.Replace(splist[0], "\\", "\\", size-1)
	return ret
}
func execCommand(commandName string, params []string) bool {
	cmd := exec.Command(commandName, params...)

	//显示运行的命令
	fmt.Println(cmd.Args)

	stdout, err := cmd.StdoutPipe()

	if err != nil {
		fmt.Println(err)
		return false
	}

	cmd.Start()

	reader := bufio.NewReader(stdout)

	//实时循环读取输出流中的一行内容
	for {
		line, err2 := reader.ReadString('\n')
		if err2 != nil || io.EOF == err2 {
			break
		}
		fmt.Println(line)
	}

	cmd.Wait()
	return true
}
func main() {
	spath := GetPathWindows()
	fmt.Println(spath)

	command := "cmd"
	params := []string{"/c", "test.bat"}
	//执行cmd命令: ls -l
	execCommand(command, params)

	//	cm := exec.Command("cmd", "/C", "dir")
	//	fmt.Println(cm.Run())

}
